//
//  PlayController.m
//  MyTrip
//
//  Created by zhang on 15/8/22.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "PlayController.h"
#import "PlayCollectionViewCell.h"
#import "MusicCollectionViewCell.h"
@interface PlayController ()<UIWebViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) UIButton *backButton;
@property (nonatomic, retain) UICollectionView *collview;

@end

@implementation PlayController
- (void)dealloc
{
    [_webView release];[_backButton release];[_collview release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    
    [self createViewController];
    [self initSegmentedControl];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:70 / 255.0f green:160 / 255.0f blue:175 / 255.0f alpha:1];
   
}
- (void)initSegmentedControl
{
  
    NSArray *array=[[NSArray alloc]initWithObjects:@"视频",@"电台", nil ];
    UISegmentedControl *segmentedControl=[[UISegmentedControl alloc]initWithItems:array];
    segmentedControl.frame=CGRectMake(35, 10, 200, 30);
    //设置按下按钮的颜色
    segmentedControl.tintColor=[UIColor colorWithRed:49.0/1000.0 green:49.0/660.0 blue:49.0/660.0 alpha:1];
    segmentedControl.selectedSegmentIndex=0;//当前默认按钮索引
    
    NSMutableDictionary *attributes=[NSMutableDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:12],NSFontAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName, nil];
    [segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
    
    NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    
    [segmentedControl setTitleTextAttributes:highlightedAttributes forState:UIControlStateHighlighted];
    
    self.navigationItem.titleView=segmentedControl;
    [segmentedControl addTarget:self action:@selector(doSomethingInSegment:)forControlEvents:UIControlEventValueChanged];
    
    
    [array release];
    
    
}


- (void)createViewController
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(self.view.frame.size.width, 667 - 64 - 49 - 5);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collview = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 667 - 64 - 49) collectionViewLayout:layout];
    self.collview.delegate = self;
    self.collview.dataSource = self;
    self.collview.pagingEnabled = YES;
    self.collview.bounces = NO;
    self.collview.scrollEnabled = NO;
    
    [self.collview registerClass:[PlayCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.collview registerClass:[MusicCollectionViewCell class] forCellWithReuseIdentifier:@"musiccell"];
    [self.view addSubview:self.collview];
    
    
    [layout release];
    [self.collview release];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 2;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item ==0) {
        PlayCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        return cell;
    }else if(indexPath.item ==1){
        MusicCollectionViewCell *musicCell=[collectionView dequeueReusableCellWithReuseIdentifier:@"musiccell" forIndexPath:indexPath];
        return musicCell;
    }
    return nil;
}

-(void)doSomethingInSegment:(id)sender
{
    
    switch ([sender selectedSegmentIndex]) {
        case 0:
        {
            self.collview.contentOffset = CGPointMake(0, 0);
        }
            break;
        case 1:
        {
            self.collview.contentOffset = CGPointMake(self.view.frame.size.width, 0);
        }
            break;
            
        default:
            break;
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
